package com.example.demo.component;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.print.DocFlavor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/***
 * 区域解析器区分登陆时显示英文还是中文
 */
public class MyLocaleResolver  implements LocaleResolver{
    //  实现两个方法用第一个
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String l=httpServletRequest.getParameter("1");
        Locale  locale =Locale.getDefault();//  使用系统默认的解析器
        if(!StringUtils.isEmpty("1")){
            String [] split=l.split("_");
            locale=new Locale(split[0],split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
